import {setCount,getCount,request,wxLogin} from "../../utils/request"
Page({
  data: {

  },
  onLoad(options) {
    console.log("home onload");
    // wxLogin()
  },
  getUserInfo(e) {
    console.log(e.detail);
    return
    request("POST",'mp/user/getUserInfo',{
      iv: e.detail.iv,
      encryptedData: e.detail.encryptedData,
    }, res => {
      wx.showToast({
        title: '授权成功!',
      })
      console.log("userinfo ---",res);
    }, err => {
      console.log("err1 ---",err);
    })
  },
  login(event) {
    wx.login({
      success: (response) => {
        // console.log("======",response.code);
        let header = {
          'content-type': 'application/x-www-form-urlencoded' 
        };
        wx.request({
          header:header,
          method:"POST",
          url: 'https://xw.psn.asia/mp/mpLogin',
          data:{
            code: response.code
          },
          success: res => {
            if(res.statusCode === 200) {
              if(res.data.code === 0) {
                wx.showToast({
                  title: '登录成功!',
                })
                wx.setStorageSync('token', res.data.data.token)
              }else {
                wx.showToast({
                  icon:"none",
                  title: res.data.message,
                })
              }
            }else {
              wx.showToast({
                icon:"none",
                title: "httpCode: "+res.statusCode,
              })
            }
          },
          fail: err => {
            console.log("mp/mpLogin error: ",err);
          }
        })
      },
    })
  },
  pageTo(event) {
    let path = event.currentTarget.dataset.path
    console.log("path====",path);
    wx.navigateTo({
      url: path,
    })
  },
  getEquipList() {
    request("POST",'mp/index/equipList',{}, res => {
      wx.showToast({
        title: '获取成功!',
      })
      console.log("res1 ---",res);
    }, err => {
      console.log("err1 ---",err);
    })
  }
})